import {
  Controller,
  Post,
  Body,
  Get,
  Param,
  Patch,
  Delete
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';
import { CompanyService } from './company.service';
import { createCompanyDto, UpdateCompanyDto } from 'libs/db/src/schemas';
import { companyNormalize as norm } from '../../normalize';
import { QueryDto } from './dto/queryDto';

@Controller(norm.path)
@ApiBearerAuth()
@ApiTags(norm.tag)
export class CompanyController {
  constructor(private readonly companyService: CompanyService) {}

  @Post(norm.create.path)
  @ApiOperation({ summary: norm.create.tag })
  async create(@Body() createUserDto: createCompanyDto) {
    return this.companyService.create(createUserDto);
  }

  @Post(norm.page.path)
  @ApiOperation({ summary: norm.page.tag })
  pageQuery(@Body() dto: QueryDto) {
    return this.companyService.pageQuery(dto);
  }

  @ApiOperation({ summary: norm.list.tag })
  @Get(norm.list.path)
  async findAll() {
    return this.companyService.findAll();
  }

  @ApiOperation({ summary: norm.detail.tag })
  @Get(norm.detail.path)
  findById(@Param(norm.detail.arg) id: string) {
    return this.companyService.findById(id);
  }

  @ApiOperation({ summary: norm.update.tag })
  @Patch(norm.update.path)
  update(
    @Param(norm.update.arg) id: string,
    @Body() updateUserDto: UpdateCompanyDto
  ) {
    return this.companyService.update(id, updateUserDto);
  }

  @ApiOperation({ summary: norm.delete.tag })
  @Delete(norm.delete.path)
  remove(@Param(norm.delete.arg) id: string) {
    return this.companyService.del(id);
  }
}
